package com.ues21.awt.controller;
import java.util.Properties;
public abstract class Controlador {
	protected static Properties config;
		static{
			try{
				config = new Properties();
				config.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("com/ues21/awt/controller/config.properties"));
			}
			catch (Exception e){
				System.out.println("Error al cargar config de controladores. Cerrando aplicacion");				
				System.exit(-1);
			}
		}
	public Controlador(){}
	
	public static void callAction(String name, ParametrosAccion pars){
		try{			
			Class c = Class.forName(config.getProperty(name+".class"));
			Controlador cont = (Controlador)c.newInstance();			
			cont.execute(name, pars);			
		}catch (Exception e){
			System.out.println("Error al llamar a la accion "+name+". Cerrando aplicacion");				
			System.exit(-1);				
		}
	}
	public static Object[] callCons(String name, ParametrosAccion pars){
		Object [] parm = new Object[4];
		try{
			Class c = Class.forName(config.getProperty(name+".class"));
			Controlador cont = (Controlador)c.newInstance();
			parm = cont.executeCons(name, pars);			
		}catch (Exception e){
			System.out.println("Error al llamar a la accion "+name+". Cerrando aplicacion");				
			System.exit(-1);				
		}
		return parm;
	}
	public abstract void execute(String name, ParametrosAccion pars);
	public abstract Object[] executeCons(String name, ParametrosAccion pars);
}
